/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.produce.data.controller.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import me.send.data.service.pojo.Manager;
import me.send.data.service.pojo.Message;
import me.send.data.service.service.ActivitySchoolFastfoodOrderService;
import me.send.data.service.service.ActivitySchoolFastfoodService;
import me.send.data.service.service.AdvertService;
import me.send.data.service.service.CityService;
import me.send.data.service.service.CommAddressService;
import me.send.data.service.service.MessageService;
import me.send.data.service.service.OrderProgressService;
import me.send.data.service.service.OrdersService;
import me.send.data.service.service.PayOrderService;
import me.send.data.service.service.TreeService;
import me.send.data.service.service.UserService;
import me.send.framework.util.HelperUtil;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author maxmin
 *
 * @date 2015年9月11日 上午10:38:00
 */
public class CommonController {
	
	@Autowired
	MessageService messageService;
	
	@Autowired
	protected CommAddressService commAddressService;
	
	@Autowired
	protected UserService userService;
	
	@Autowired
	protected OrderProgressService orderProgressService;
	
	@Autowired
	protected PayOrderService payOrderService;
	
	@Autowired
	protected OrdersService ordersService;

	@Autowired
	protected TreeService treeService;
	
	@Autowired
	protected AdvertService advertService;
	
	@Autowired
	protected CityService cityService;

	@Autowired
	protected ActivitySchoolFastfoodService activitySchoolFastfoodService;
	
	@Autowired
	protected ActivitySchoolFastfoodOrderService activitySchoolFastfoodOrderService;
	
	/**
	 * 获取当前登录的manager
	 * @param request
	 * @return
	 * @author maxmin
	 * @date 2015年9月15日下午5:25:05
	 */
	public Manager getCurrentManager(HttpServletRequest request){
		HttpSession session = request.getSession();
		Object object = session.getAttribute("currentUser");
		Manager manager = null;
		if (object!=null) {
			manager = (Manager)object;
		}
		return manager;
	}
	
	/**
	 * 
	 * @param userId 用户或者经纪人id
	 * @param message 消息内容
	 * @param userType 
	 */
	protected void saveMessage(Message message) {
		try {
			message.setCreatetime(HelperUtil.getCurrentDate());
			message.setUpdatetime(HelperUtil.getCurrentDate());
			messageService.addMessage(message);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
